<template>
  <div>
    <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[1, 2, 5, 10, 15, 20]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="props.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'

const props = defineProps<{ total: number }>()

const pageSize = ref(5)
const currentPage = ref(1)
const small = ref(false)
const background = ref(false)
const disabled = ref(false)

const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`)
  emit('changepageSize', val)
}

// 改变当前页
const emit = defineEmits<{
  (e: 'changepageSize', val: number): void
  (e: 'changeCurrentPage', val: number): void
}>()
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`)
  emit('changeCurrentPage', val)
}
</script>

<style lang="scss" scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>
